<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">{{name}}<name-component></name-component></div>
  <script src="../node_modules/vue/dist/vue.js"></script>
  <script>
    const NameComponent = {
      mounted: () => {
        console.log('我是子组件的-------')
      },
      template: `<h1>我是子组件</h1>`
    }

    Vue.mixin({
      mounted() {
        console.log('测试mixin混入')
      },
    })
    new Vue({
      el: '#app',
      components: {
        NameComponent
      },
      created() {
        console.log('created')
      },
      mounted() {
        console.log('mounted')
      },
      data() {
        return {
          name: 'lihh',
          arr: [1, 2, 3, 4]
        }
      }
    })

    // -------------- 下面是默认策略钩子 -----------------
    const strats = Object.create(null)
    const LIFECYCLE_HOOKS = [
      'beforeCreate',
      'created',
      'beforeMount',
      'mounted',
      'beforeUpdate',
      'updated',
      'beforeDestroy',
      'destroyed',
      'activated',
      'deactivated',
      'errorCaptured',
      'serverPrefetch'
    ]

    LIFECYCLE_HOOKS.forEach(method => {
      strats[method] = function(parentVal, childVal) {
        const res = childVal
          ? parentVal
            ? parentVal.concat(childVal)
            : Array.isArray(childVal)
            ? childVal
            : [childVal]
          : parentVal;
        return res ? dedupeHooks(res) : res;
      }
    })
  </script>
</body>
</html>